package com.example.jwt.framework.security.handle;

import com.alibaba.fastjson2.JSON;
import com.example.jwt.common.constant.Constants;
import com.example.jwt.common.core.AjaxResult;
import com.example.jwt.common.util.ServletUtils;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @version 1.0.0
 * @className: CustomAuthenticationSuccessImpl
 * @description: 登录成功处理类
 * @author: LiJunYi
 * @create: 2022/7/26 13:30
 */
@Component
public class CustomAuthenticationSuccessImpl implements AuthenticationSuccessHandler
{

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication e) {
        ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.success(Constants.LOGIN_SUCCESS)));
    }
}
